/*
 * Created on 22.10.2003
 * Local Projects Database
 * Mihai Postelnicu (mihai@ro-gateway.org)
 * (c) 2003 by eRomania Gateway
 */
package ro.gateway.aida.utils;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;



/**
 * @author Mihai Postelnicu
 *  This is a wrapper for an ArrayList, that maintains localized content.
 *  The purpose is that all added items should first be localised
 *  e-mail (mihai@ro-gateway.org)
 * (c) 2003 by eRomania Gateway
 */

public class LocalisedSortableList extends SortedList implements Localizable
{
      protected String viewLang;

      public LocalisedSortableList( String lang )
      {
            this.viewLang = lang;
      }

      public LocalisedSortableList()
      {
      }

      public LocalisedSortableList( String lang, Comparator c )
      {
            super( c );
            this.viewLang = lang;
      }

      public LocalisedSortableList( Comparator c )
      {
            super( c );
      }

      public LocalisedSortableList( String lang, Comparator c, List l )
      {
            super( c, l );
            this.viewLang = lang;
      }

      public boolean add( Localizable item )
      {
            if ( viewLang != null ) item.setViewLang( viewLang );
            return super.add( item );
      }

      public void setViewLang( String lang )
      {
            Iterator i = iterator();
            this.viewLang = lang;
            while ( i.hasNext() )
            {
                  Localizable item = ( Localizable ) i.next();
                  item.setViewLang( lang );
            }
      }

      public String getViewLang()
      {
            return viewLang;
      }
}
